package com.ddwl.message.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.message.service.AdvertService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.message.AdvertBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.message.AdvertVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author Fu Zhaohui
 * @date 2017/2/5
 */
@Api(tags="广告服务")
@RequestMapping("advert")
@RestController
public class AdvertController extends BaseController {

    @Resource
    private AdvertService advertService;

    @GetMapping("index")
    @Auth(required = false)
    @ApiOperation("获取广告")
    public RestVo<AdvertVo> index(@RequestParam(required = false, defaultValue = "index") String position) {
        return RestVo.ok(advertService.index(position));
    }

    @GetMapping("/page")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("获取广告列表")
    public RestVo<PageVo<AdvertVo>> page(@RequestBody PageBo<AdvertBo> pageBo) {
        return RestVo.ok(advertService.page(pageBo));
    }

    @PostMapping("/save")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("保存广告")
    public RestVo save(@Valid @RequestBody AdvertBo bo) {
        return RestVo.ok(advertService.save(bo));
    }
}
